package com.example.qqviewspringboot.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${media.storage.path}")
    private String mediaStoragePath;

    @Value("${avatar.storage.path}")
    private String avatarStoragePath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射 /uploads/**
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + mediaStoragePath + "/");

        // 映射 /avatars/**
        registry.addResourceHandler("/avatars/**")
                .addResourceLocations("file:" + avatarStoragePath + "/");
    }
}
